package com.web.orderservice.controller;

import com.web.orderservice.client.ProductServiceFeignClient;
import com.web.orderservice.entity.Order;
import com.web.orderservice.entity.Product;
import com.web.orderservice.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @Resource
    private ProductServiceFeignClient productServiceFeignClient;

    @RequestMapping("/order/{id}")
    public ResponseEntity<Order> findProductById(@PathVariable Integer id){
        Order order = orderService.getById(id);
        //使用feign客户端调用商品服务
        ResponseEntity<Product> entity = productServiceFeignClient.findProductById(order.getProductId());
        order.setProduct(entity.getBody());
        return ResponseEntity.ok(order);
    }
}
